package com.gf.common.lucene;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.gf.common.lucene.service.LuceneSynchroService;

/**
 * lucene同步<br>
 * 每15分钟更新一次
 * 
 * @author zhuguifeng
 * 
 */ 

@Component("luceneJob")
public class LuceneJob {

	private Log log = LogFactory.getLog(LuceneJob.class);

	@Autowired
	private LuceneSynchroService luceneSynchroService;

	//@PostConstruct
	public void init() {
		log.info("lucene init  begin...");
		
		luceneSynchroService.updateTimstamp();
		luceneSynchroService.rebuild();
		
		log.info("lucene init  end...");
	}

	/**
	 * 开始进行同步<br>
	 * spring配置为每15分钟更新一次
	 */
	public void beginSynchro() {
		log.info("lucene update  begin...");
		
		luceneSynchroService.checkTimestamp();
		luceneSynchroService.updateTimstamp();
		luceneSynchroService.synchro();
		
		log.info("lucene update  end...");
	}

	/**
	 * 重新建索引<br>
	 * 每30天一次
	 */
	public void rebuild() {
		log.info("lucene rebuild begin...");
		
		luceneSynchroService.rebuild();
		
		log.info("lucene rebuild end...");
	}

}
